home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lantools / blueprnt / bpmount.asm < prev    next >
Assembly Source File  |  1989-11-28  |  12KB  |  435 lines

  1. page 60,132
  2. title   BP-LAN Shared Disk Device Driver
  3. ;**************************************************************
  4. ;* BP-LAN Shared Disk Device Driver (BPMOUNT.ASM,BPMOUNT.SYS) *
  5. ;* by Craig Chaiken                                           *
  6. ;* November 28, 1989                                          *
  7. ;*                                                            *
  8. ;* Function:                                                  *
  9. ;*     Allows PC Compatible Client to Access any Block Device *
  10. ;*     on the Server Computer as if it were a local device.   *
  11. ;* Command Format:                                            *
  12. ;*     DEVICE=BPMOUNT.SYS /remote_drive /socket_num           *
  13. ;*                      /write_protect_flag /max_sector_size  *
  14. ;**************************************************************
  15. code    segment public  'CODE'
  16.         assume  cs:code,ds:code,es:code;
  17.  
  18.         org     0
  19. ;
  20. ;*** Device Driver Header ***
  21. ;
  22. header  dd      -1      ;link to next device (assume this to be the last)
  23.         dw      2000h   ;device attribute = block device
  24.         dw      strat   ;strategy entry point
  25.         dw      intr    ;interrupt entry point
  26. blkdev  db      1       ;one block device
  27.         db      'BP'    ;indicate that device is a BP-LAN Drive
  28. version db      10h     ;BP-LAN Version 1.0
  29. socket_num      db      ?
  30. local_drive     db      3    ;default drive D:
  31. remote_drive    db      2    ;default drive C:
  32. write_protect   db      0    ;default no write protection
  33. ;
  34. rh_ptr  dd      ?       ;Pointer to Request Header
  35. ;
  36. ;*** MSDOS Command Code Vector Table ***
  37. ;
  38. vector_table:
  39.         dw      init            ; 0 = initialize driver
  40.         dw      media_check     ; 1 = media_check on block device
  41.         dw      build_bpb       ; 2 = build BIOS parameter block
  42.         dw      bad
  43.         dw      read            ; 4 = read from device
  44.         dw      bad,bad,bad
  45.         dw      write           ; 8 = write to device
  46.         dw      write_verify    ; 9 = write with verify
  47.  
  48.         include bpbioshd.mod
  49.         include misc.mod
  50.         include console.mod
  51.  
  52. packet_length   dw      ?
  53. socket_error    db      ?
  54. ;
  55. ;*** Strategy Routine ***
  56. ;
  57. strat   proc    far
  58.         mov     word ptr cs:[rh_ptr],bx
  59.         mov     word ptr cs:[rh_ptr+2],es
  60.         ret
  61. strat   endp
  62.  
  63. ;
  64. ;*** Interrupt Routine ***
  65. ;
  66. intr    proc    far
  67.         pushf
  68.         push    ax
  69.  
  70. ;        cli                                     ;install local stack
  71. ;        mov     cs:stackseg,ss
  72. ;        mov     cs:stackptr,sp
  73. ;        mov     ax,cs
  74. ;        mov     ss,ax
  75. ;        mov     sp,offset local_stack
  76. ;        sti
  77.  
  78.         push    bx
  79.         push    cx
  80.         push    dx
  81.         push    ds
  82.         push    es
  83.         push    di
  84.         push    si
  85.         push    bp
  86.  
  87.         mov     ax,cs
  88.         mov     ds,ax
  89.         les     di,cs:rh_ptr
  90.         xor     bx,bx
  91.         mov     bl,es:[di+2]            ;jump if legal command number
  92.         cmp     bx,9
  93.         jle     intr1
  94.         mov     ax,3                    ;unknown command
  95.         jmp     short error
  96.  
  97. intr1:
  98.         shl     bx,1
  99.         mov     si,offset vector_table
  100.         jmp     word ptr cs:[si+bx]
  101. error:
  102.         or      ax,800Ch
  103.         cmp     cs:write_protect,0
  104.         jz      success
  105.         and     ax,0ff00h               ;indicate write protect error
  106. success:
  107.         or      ax,0100h                ;set done bit
  108.         les     di,cs:rh_ptr
  109.         mov     es:[di+3],ax            ;return status word
  110.  
  111.         pop     bp
  112.         pop     si
  113.         pop     di
  114.         pop     es
  115.         pop     ds
  116.         pop     dx
  117.         pop     cx
  118.         pop     bx
  119.  
  120. ;        cli                             ;restore stack
  121. ;        mov     sp,cs:stackptr
  122. ;        mov     ss,cs:stackseg
  123. ;        sti
  124.         pop     ax
  125.         popf
  126.         ret
  127. intr    endp
  128.  
  129.  
  130. ;
  131. ;*** Set Done Status for All Unsupported Command Codes ***
  132. ;
  133. bad     proc    near
  134.         xor     ax,ax
  135.         jmp     success
  136. bad     endp
  137.  
  138. ;
  139. ;***  Media Check -- Assume Network Drive is Fixed Disk ***
  140. ;
  141. media_check     proc    near
  142.         mov     word ptr packet_length,2
  143.         mov     packet_buffer,'M'
  144.         mov     al,remote_drive
  145.         mov     packet_buffer[1],al
  146.         put_packet socket_num,packet_length,offset packet_buffer
  147.         get_packet
  148.         mov     al,packet_buffer[2]
  149.         mov     byte ptr es:[di+14],al          ;media not changed
  150.         xor     ax,ax
  151.         jmp     success
  152. media_check     endp
  153.  
  154. ;
  155. ;*** Build BIOS Parameter Block ***
  156. ;
  157. build_bpb       proc    near
  158.         mov     word ptr es:[di+18],offset bpb
  159.         mov     es:[di+20],cs
  160.         call    getboot ;get drive configuration data
  161.         xor     ax,ax
  162.         jmp     success
  163. build_bpb       endp
  164.  
  165. ;
  166. ;*** Read from Block Device ***
  167. ;
  168. read    proc    near
  169.         mov     function,0
  170.         jmp     io
  171. read    endp
  172.  
  173. reasec  proc    near            ;*** Read an Absolute Sector From Hub ***
  174.         mov     word ptr packet_length,4
  175.         mov     packet_buffer,'R'
  176.         mov     al,remote_drive
  177.         mov     packet_buffer[1],al
  178.         mov     cx,startsect
  179.         mov     packet_buffer[2],cl
  180.         mov     packet_buffer[3],ch
  181.         put_packet socket_num,packet_length,offset packet_buffer
  182.         get_packet
  183.         mov     cx,cs:seclen
  184.         ret
  185. reasec  endp
  186.  
  187. ;
  188. ;*** Write to Block Device ***
  189. ;
  190. write_verify:
  191. write   proc    near
  192.         cmp     cs:write_protect,0
  193.         jz      write1
  194.         jmp     error           ;write protect error
  195. write1: mov     function,1
  196.         jmp     io
  197. write   endp
  198.  
  199. wrisec  proc    near
  200.         mov     packet_buffer,'W'
  201.         mov     al,remote_drive
  202.         mov     packet_buffer[1],al
  203.         mov     cx,startsect
  204.         mov     packet_buffer[2],cl
  205.         mov     packet_buffer[3],ch
  206.         mov     cx,cs:seclen
  207.         mov     word ptr packet_length,cx
  208.         add     word ptr packet_length,4
  209.         put_packet socket_num,packet_length,offset packet_buffer
  210.         ret
  211. wrisec  endp
  212.  
  213. ;
  214. ;*** Generic Disk I/O Handler ***
  215. ;
  216. io      proc    near
  217.         mov     ax,es:[di+14]           ;Data Transfer Address
  218.         mov     dtaoff,ax
  219.         mov     ax,es:[di+16]
  220.         mov     dtaseg,ax
  221.         mov     ax,es:[di+18]           ;# sectors
  222.         mov     numsectors,ax
  223.         mov     ax,es:[di+20]           ;starting sector
  224.         mov     startsect,ax
  225.         push    es
  226.         push    di
  227.  
  228. io1:    mov     ax,numsectors           ;exit if sectors = 0
  229.         or      ax,ax
  230.         jz      io5
  231.  
  232.         mov     es,dtaseg
  233.         mov     al,function
  234.         or      al,al
  235.         jnz     io2
  236.         cmp     startsect,0
  237.         jnz     io4a
  238.         call    getboot
  239.     jmp    io3
  240. io4a:   call    reasec
  241.         jmp     io3
  242.  
  243. io2:    push    cx
  244.         push    si
  245.         push    di
  246.         mov     si,dtaoff
  247.         lea     di,packet_buffer+4
  248.         mov     cx,cs:seclen
  249.         call    essitodi
  250.         pop     di
  251.         pop     si
  252.         pop     cx
  253.         call    wrisec
  254.         jmp     io4
  255.  
  256. io3:    pop     di
  257.         push    di
  258.         push    cx
  259.         push    si
  260.         push    di
  261.         lea     si,packet_buffer+4
  262.         mov     di,dtaoff
  263.         mov     es,dtaseg
  264.         mov     cx,cs:seclen
  265.         call    sitoesdi
  266.         pop     di
  267.         pop     si
  268.         pop     cx
  269.  
  270. io4:    pop     di
  271.         push    di
  272.         dec     numsectors
  273.         inc     startsect
  274.         push    di
  275.         mov     di,dtaoff
  276.         add     di,cs:seclen
  277.         mov     dtaoff,di
  278.         jnc     sameseg
  279.         mov     ax,es
  280.         add     ax,1000h
  281.         mov     es,ax
  282.         mov     dtaseg,ax
  283. sameseg: pop    di
  284.         jmp     io1
  285.  
  286. io5:    pop     di
  287.         pop     es
  288.         cmp     socket_error,0
  289.         jnz     io6
  290.         call    ewrite
  291.         jmp     success
  292. io6:    mov     ax,word ptr packet_buffer[2]
  293.         call    ewrite
  294.         jmp     error
  295.  
  296. ewrite: mov     al,function
  297.         cmp     al,1
  298.         jnz     ewrit1
  299.         mov     packet_buffer,'T'
  300.         mov     word ptr packet_length,2
  301.         put_packet socket_num,packet_length,offset packet_buffer
  302. ewrit1: ret
  303. io      endp
  304.  
  305. getboot proc    near            ;*** Get Drive Conf. from Boot Sector ***
  306.         push    cs
  307.         pop     ds
  308.     mov     startsect,0
  309.     call    reasec
  310.     lea     di,packet_buffer+4
  311.         mov     ax,[di+0bh]
  312.         mov     seclen,ax       ;get bytes/sector
  313.         mov     al,[di+0dh]
  314.         mov     clulen,al       ;get sectors/cluster
  315.         mov     ax,[di+0eh]
  316.         mov     numres,ax       ;get number of reserved sectors
  317.         mov     al,[di+10h]
  318.         mov     numfat,al       ;get number of fats
  319.         mov     ax,[di+11h]
  320.         mov     numdir,ax       ;get number of root dir entries
  321.         mov     ax,[di+13h]
  322.         mov     numsec,ax       ;get total number of sectors
  323.         mov     al,[di+15h]
  324.         mov     medtyp,al       ;get media descriptor byte
  325.         mov     ax,[di+16h]
  326.         mov     fatlen,ax       ;get sectors/fat
  327.         ret
  328. getboot endp
  329.  
  330. ;
  331. ;*** BPB ***
  332. ;
  333. bpb_vec dw      offset  bpb
  334.  
  335. bpb:            ;Sample Values, Replaced by Getboot Procedure
  336. seclen  dw      512             ;Bytes/Cluster
  337. clulen  db      1               ;Sectors/Cluster
  338. numres  dw      1               ;Reserved Sectors
  339. numfat  db      2               ;Number of FATs
  340. numdir  dw      0e0h            ;Number of Directory Entries
  341. numsec  dw      960h            ;Number of Sectors
  342. medtyp  db      0f9h            ;Media Type
  343. fatlen  dw      7               ;Sectors/FAT
  344.  
  345. ;
  346. ;*** Variables ***
  347. ;
  348. function        db      ?
  349. startsect       dw      ?
  350. numsectors      dw      ?
  351. dtaseg          dw      ?
  352. dtaoff          dw      ?
  353. stackptr        dw      ?
  354. stackseg        dw      ?
  355. ;
  356. ;*** Local Stack ***
  357. ;
  358. even
  359.                 dw      3fh     dup (?)
  360. local_stack     dw      ?
  361.  
  362. packet_buffer   db      ?
  363.  
  364. ;
  365. ;*** Messages ***
  366. ;
  367. mess1   db      'Mounting Server Drive ',0
  368. mess2   db      ': as Client Drive ',0
  369.  
  370. ;
  371. ;*** initialize ***
  372. ;
  373. init    proc    near
  374.         push    di
  375.         push    si
  376.         push    ds
  377.  
  378.         push    di
  379.         lea     di,mess1
  380.         call    messout
  381.         pop     di
  382.  
  383.         mov     ax,es:[di+20]
  384.         mov     ds,ax
  385.         mov     si,es:[di+18]
  386.         call    wslash
  387.         call    charout
  388.         sub     al,41h
  389.         mov     cs:remote_drive,al
  390.  
  391.         push    di
  392.         push    ds
  393.         push    cs
  394.         pop     ds
  395.         lea     di,mess2
  396.         call    messout
  397.         pop     ds
  398.         pop     di
  399.         mov     al,es:[di+22]
  400.         mov     cs:local_drive,al
  401.         add     al,41h
  402.         call    charout
  403.         mov     al,':'
  404.         call    charout
  405.         mov     al,13
  406.         call    charout
  407.         mov     al,10
  408.         push    cx
  409.         call    charout
  410.         call    get_opt
  411.         jb      default
  412.         mov     cs:socket_num,cl
  413.         call    get_opt
  414.         jb      default
  415.         mov     cs:write_protect,cl
  416.         call    get_opt
  417.         jb      default
  418.         mov     cs:seclen,cx
  419. default:pop     cx
  420.         pop     ds
  421.         pop     si
  422.         pop     di
  423.         mov     byte ptr es:[di+13],1                           ;# units
  424.         mov     word ptr es:[di+14],offset packet_buffer        ;break address
  425.         mov     ax,cs:seclen
  426.         add     ax,16
  427.         add     word ptr es:[di+14],ax          ;allocate space for buffer
  428.         mov     word ptr es:[di+16],cs
  429.         mov     word ptr es:[di+18],offset bpb_vec
  430.         mov     es:[di+20],cs
  431.         jmp     success
  432. init    endp
  433. code    ends
  434.         end
  435.